<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
FlyUI Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="mvcutils.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>mvcutils.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This script defines some MVC utilities.
 <BR/><BR/><B>Version: </B>$Revision:538 $ on $Date: 2008-08-14 10:36:17 +0100 (Thu, 14 Aug 2008) $ by $Author: aliman $
 TODO license terms<BR/><BR/><B>Requires:</B><UL>- YAHOO.log<BR/>- YAHOO.util.Dom</UL><B>Author:</B> <a href="http://purl.org/net/aliman">Alistair Miles</a>
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/mvcutils/GenericModel.html">flyui.mvcutils.GenericModel</a></b></td>
    <td>A generic model class for an MVC widget or application.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span>
 * This script defines some MVC utilities.
 * <span class="attrib">@requires</span> YAHOO.log
 * <span class="attrib">@requires</span> YAHOO.util.Dom
 * <span class="attrib">@author</span> &lt;a href="http://purl.org/net/aliman"&gt;Alistair Miles&lt;/a&gt;
 * <span class="attrib">@version</span> $Revision:538 $ on $Date: 2008-08-14 10:36:17 +0100 (Thu, 14 Aug 2008) $ by $Author: aliman $
 * TODO license terms
 */</span>
 
 
<span class="comment">// Shortcuts</span>
var log = YAHOO.log;


<span class="comment">// create a namespace if not already defined</span>
flyui.namespace(<span class="literal">"flyui.mvcutils"</span>);


<span class="comment">/** 
 * <span class="attrib">@class</span>
 * A generic model class for an MVC widget or application.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {Object} definition the definition of the model
 */</span>
flyui.mvcutils.GenericModel = <span class="reserved">function</span>( definition ) {
	
	
	var _this = <span class="reserved">this</span>;
	
	
	<span class="comment">/** Private data object storing the model.
	 */</span>
	var _data = new Object();
	
	
	<span class="comment">/** Private array of property names.
	 */</span>
	var _propertyNames = definition.propertyNames;
	
	
	<span class="comment">/** Private definition of controller property values.
	 */</span>
	var _controlledValues = definition.controlledValues;
		
		
	<span class="comment">/** Private map of listener functions.
	 * (Map each property name to an array of listener functions.)
	 */</span> 
	var _listeners = new Object();
	
	
	<span class="comment">/** Initialise the model object.
	 * <span class="attrib">@private</span>
	 */</span> 
	<span class="reserved">this</span>._init = <span class="reserved">function</span>() {
		
		<span class="comment">// initialise listeners</span>
		<span class="reserved">for</span> (var i=0; i&lt;_propertyNames.length; i++) {
			_listeners[_propertyNames[i]] = new Array();
		}

		<span class="comment">// initialise the model data</span>
		definition.initialize(_data);	
		
	}
	
	
	<span class="comment">// complete initialisation</span>
	<span class="reserved">this</span>._init();
	
	
	<span class="comment">/** Get a property of the model.
	 * <span class="attrib">@param</span> {String} propertyName the name of the property to get
	 */</span>
	<span class="reserved">this</span>.get = <span class="reserved">function</span>( propertyName ) {
		_this._validatePropertyName(propertyName);
		<span class="reserved">return</span> _data[propertyName];
	}
	
	
	<span class="comment">/** Set a propert of the model (all listeners will be notified of the change).
	 * <span class="attrib">@param</span> {String} propertyName the name of the property to set
	 * <span class="attrib">@param</span> {Any} value the new value of the property
	 */</span>
	<span class="reserved">this</span>.set = <span class="reserved">function</span>( propertyName, value ) {
		_this._validatePropertyValuePair(propertyName, value);
		var oldValue = _data[propertyName]; <span class="comment">// store the old value</span>
		_data[propertyName] = value; <span class="comment">// set the new value</span>
		_this._notifyListeners(propertyName, oldValue, value); <span class="comment">// notify the change</span>
	}
	
	
	<span class="comment">/** Validate a property name.
	 * <span class="attrib">@param</span> {String} propertyName the name of the property to validate
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._validatePropertyName = <span class="reserved">function</span>( propertyName ) {
		var valid = false;
		<span class="reserved">for</span> (var i=0; i&lt;_propertyNames.length; i++) {
			<span class="reserved">if</span> (_propertyNames[i] == propertyName) valid = true;
		}
		<span class="reserved">if</span> (!valid) {
			throw {name:<span class="literal">"InvalidPropertyNameError"</span>, message:<span class="literal">"Invalid property name: "</span>+propertyName};
		}
	}
	
	
	<span class="comment">/** Validate a property value pair.
	 * <span class="attrib">@param</span> {String} propertyName the name of the property to validate
	 * <span class="attrib">@param</span> {Any} value the property value to validate
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._validatePropertyValuePair = <span class="reserved">function</span>( propertyName, value ) {
		var valid = false;
		_this._validatePropertyName(propertyName);
		var values = _controlledValues[propertyName];
		<span class="reserved">if</span> (values) {
			<span class="reserved">for</span> (var i=0; i&lt;values.length; i++) {
				<span class="reserved">if</span> (value == values[i]) {
					valid = true;
				}	
			}
		} <span class="reserved">else</span> {
			valid = true;
		}
		<span class="reserved">if</span> (!valid) {
			throw {name:<span class="literal">"InvalidPropertyValuePairError"</span>, message:<span class="literal">"Invalid property-value pair, property name: "</span>+propertyName+<span class="literal">", property value: "</span>+value};
		}
	}


	<span class="comment">/** Add a property change listener to this model.
	 * <span class="attrib">@param</span> {Function} listener a function to call if the model changes
	 */</span>
	<span class="reserved">this</span>.addListener = <span class="reserved">function</span>( propertyName, listener ) {
		flyui.debug(<span class="literal">"addListener, "</span>+propertyName);
		_this._validatePropertyName(propertyName);
		var propListeners = _listeners[propertyName];
		propListeners[propListeners.length] = listener;
	}
		
		
	<span class="comment">/** Notify all listeners of a property change.
	 * <span class="attrib">@param</span> {String} propertyName the name of the property to validate
	 * <span class="attrib">@param</span> {Any} oldValue the old property value
	 * <span class="attrib">@param</span> {Any} newValue the new property value
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._notifyListeners = <span class="reserved">function</span>( propertyName, oldValue, newValue ) {
		flyui.debug(<span class="literal">"notifyListeners, "</span>+propertyName);
		var propListeners = _listeners[propertyName];
		<span class="reserved">for</span> (var i=0; i&lt;propListeners.length; i++) {
			var listener = propListeners[i];
			listener(oldValue, newValue);
		}
	}
	
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Dec  9 11:08:18 2008</div>
</body>
</html>
